﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.world {
    import flash.events.*;
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.world.vos.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class InitMissionCommand extends Command {

		[Inject]
        public var event:InfoEvent;
		[Inject]
        public var missions:MissionModel;
		[Inject]
        public var tutorial:TutorialModel;
		[Inject]
        public var user:UserModel;
		[Inject]
        public var letters:LetterModel;
		[Inject]
        public var tutorialModel:TutorialModel;

        override public function execute():void{
            var _local1:RequestEvent;
            if (this.missions.defaultMission.id){
                this.initButton();
            } else {
                if ((((((this.user.level >= GameConstants.MIN_LEVEL_FOR_MISSIONS)) && ((this.tutorialModel.state >= TutorialModel.ROOMTUTORIAL_CLICK_ON_MISSIONS)))) && (!(this.missions.pendingMissionCreate)))){
                    this.missions.pendingMissionCreate = true;
                    _local1 = new RequestEvent(EventConstants.SEND_REQUEST, this.onCreate);
                    _local1.addRequest("create_mission");
                    dispatch(_local1);
                } else {
                    this.hideMissions();
                };
            };
        }
        private function onCreate(_arg1:ResultVO):void{
            this.missions.pendingMissionCreate = false;
            var _local2:Object = _arg1.data.create_mission;
            if (((_arg1.success) && (_local2))){
                this.missions.addDefaultMission(_local2, true);
                this.initButton();
            } else {
                this.hideMissions();
            };
        }
        private function initButton():void{
            var _local1:MissionVO;
            if (!this.user.isVisitFriendsMode()){
                _local1 = this.missions.defaultMission;
                if (_local1.id){
                    if (_local1.isSolved){
                        dispatch(new InfoEvent(EventConstants.ON_SOLVED_MISSION, _local1.id));
                    };
                    dispatch(new Event(EventConstants.SHOW_MISSIONS));
                    if (this.event.id){
                        dispatch(new Event(this.event.id));
                    };
                } else {
                    this.hideMissions();
                };
            } else {
                this.hideMissions();
            };
        }
        private function hideMissions():void{
            dispatch(new Event(EventConstants.HIDE_MISSIONS));
        }

    }
}//package net.wooga.pets.controllers.world 
